package io.renren.modules.crud.controller;

import java.util.Arrays;
import java.util.Map;

import com.tencent.common.pojo.Result;
import com.tencent.common.pojo.StatusCode;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.crud.entity.BorrowerEntity;
import io.renren.modules.crud.service.BorrowerService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 借款表
 *
 * @author syh
 * @email sunlightcs@gmail.com
 * @date 2022-05-21 10:31:00
 */
@RestController
@RequestMapping("crud/borrower")
public class BorrowerController {
    @Autowired
    private BorrowerService borrowerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("crud:borrower:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = borrowerService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{borrowId}")
    @RequiresPermissions("crud:borrower:info")
    public R info(@PathVariable("borrowId") Integer borrowId){
		BorrowerEntity borrower = borrowerService.getById(borrowId);

        return R.ok().put("borrower", borrower);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("crud:borrower:save")
    public R save(@RequestBody BorrowerEntity borrower){
		borrowerService.save(borrower);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("crud:borrower:update")
    public R update(@RequestBody BorrowerEntity borrower){
		borrowerService.updateById(borrower);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("crud:borrower:delete")
    public R delete(@RequestBody Integer[] borrowIds){
		borrowerService.removeByIds(Arrays.asList(borrowIds));

        return R.ok();
    }

    /**
     * 审核更改状态
     * @param borrowId
     * @param infoStatus
     */
    @RequestMapping("examination")
    public void examination(@RequestParam("borrowId") Integer borrowId,@RequestParam("infoStatus") Integer infoStatus){
        borrowerService.examination(borrowId,infoStatus);
    }

    /**
     * 计算利息
     * @param borrowerEntity
     * @return
     */
    @RequestMapping("computer")
    public Result computer(@RequestBody BorrowerEntity borrowerEntity){
        return borrowerService.computer(borrowerEntity);
    }

}
